#!/bin/bash
if [ -f /etc/mongod.conf ] ; then
    sudo sed -i "s/#auth=true/auth=true/" /etc/mongod.conf
    sudo sed -i "s/#port=27017/port=30000/" /etc/mongod.conf
fi

MONGO_LOG=/tmp/mongo-pro.log
mongo 127.0.0.1:30000/admin > ${MONGO_LOG}  <<EOF
db.system.users.remove({})
use admin
db.createUser({"user": "mongo", "pwd": "mongo","roles" : [ { role: "root",db:"admin"}]})
use com-foxit-storage
db.createUser({"user": "mongo", "pwd": "mongo","roles" : [ { role: "dbOwner",db:"com-foxit-storage"}]})
db.createUser({"user": "foxitpcs", "pwd": "apF9eCXZRPdv8v0D29Pd6hdJrZJNua","roles" : [ { role: "dbOwner",db:"com-foxit-storage"}]})
use com-foxit-user-center
db.createUser({"user": "mongo", "pwd": "mongo","roles" : [ { role: "dbOwner",db:"com-foxit-user-center"}]})
db.createUser({"user": "foxitpcs", "pwd": "apF9eCXZRPdv8v0D29Pd6hdJrZJNua","roles" : [ { role: "read",db:"com-foxit-storage"}]})
EOF

echo "MongoDB initialized, log file is at ${MONGO_LOG}."
touch /tmp/MONGOINITED-PRO

echo "restart mongodb "
sudo systemctl restart mongod